package com.yizhubao.app.customviews;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.yizhubao.app.R;
import com.yizhubao.app.customviews.inter.CompleteCallBack;
import com.yizhubao.app.customviews.inter.OthersCallBack;

import h.framework.pacy.P;

/**
 * 创建人: PACY
 * 创建时间: 6/7/21 3:54 PM
 * 邮箱: pengwwe457621023@qq.com
 * 类描述: 弹窗封装
 */
public class BottomDialog {
    private String title;
    private String message;
    private Context mContext;
    private CompleteCallBack completeCallBack;
    private OthersCallBack othersCallBack;

    private String cancleText;
    private String completeText;

    public BottomDialog(@NonNull Context context, String title, String message,
                        CompleteCallBack completeCallBack,OthersCallBack othersCallBack,String completeText,String cancleText) {
        this.message = message;
        this.mContext = context;
        this.title = title;
        this.completeCallBack=completeCallBack;
        this.othersCallBack=othersCallBack;
        this.completeText=completeText;
        this.cancleText=cancleText;
    }

    public BottomDialog(@NonNull Context context) {
        this.mContext = context;
    }

    public void show() {
        View view = View.inflate(mContext, R.layout.bottom_dialog_layout, null);
        BottomSheetDialog dialog = new BottomSheetDialog(mContext, R.style.BottomSheetDialog);
        TextView title = view.findViewById(R.id.title);
        title.setText(this.title);
        TextView message = view.findViewById(R.id.content);
        message.setText(this.message);
        TextView bigComplete_tv=view.findViewById(R.id.bigComplete_tv);
        TextView twoBtnCopmlete_tv=view.findViewById(R.id.twoBtnCopmlete_tv);
        TextView twoBtnCancle_tv=view.findViewById(R.id.twoBtnCancle_tv);
        if(completeText!=null){
            bigComplete_tv.setText(completeText);
            twoBtnCopmlete_tv.setText(completeText);
        }

        if(cancleText!=null){
            twoBtnCancle_tv.setText(cancleText);
        }
        bigComplete_tv.setOnClickListener(v -> {
            if(completeCallBack!=null){
                completeCallBack.onComplete();
            }
            dialog.dismiss();
        });

        twoBtnCopmlete_tv.setOnClickListener(v -> {
            if(completeCallBack!=null){
                completeCallBack.onComplete();
            }
            dialog.dismiss();
        });

        twoBtnCancle_tv.setOnClickListener(v -> {
            if(othersCallBack!=null){
                othersCallBack.onOther();
            }
            dialog.dismiss();
        });

        LinearLayout twoBtn_lin=view.findViewById(R.id.twoBtn_lin);
        if(othersCallBack==null){
            twoBtn_lin.setVisibility(View.GONE);
            bigComplete_tv.setVisibility(View.VISIBLE);
        }else{
            twoBtn_lin.setVisibility(View.VISIBLE);
            bigComplete_tv.setVisibility(View.GONE);
        }

        dialog.setContentView(view);
        dialog.show();
    }

    public static Builder DialogBuilder(Context context) {
        Builder build = new Builder(context);
        return build;
    }


    public static class Builder {
        private String title;
        private String message;
        private Context context;
        private CompleteCallBack completeCallBack;
        private OthersCallBack othersCallBack;
        private String cancleText;
        private String completeText;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder completeCallBack(CompleteCallBack completeCallBack) {
            this.completeCallBack = completeCallBack;
            return this;
        }

        public Builder othersCallBack(OthersCallBack othersCallBack) {
            this.othersCallBack = othersCallBack;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public Builder cancleText(String cancleText) {
            this.cancleText = cancleText;
            return this;
        }

        public Builder completeText(String completeText) {
            this.completeText = completeText;
            return this;
        }

        public void show() {
            BottomDialog dialog = new BottomDialog(context, title, message,completeCallBack,othersCallBack,completeText,cancleText);
            dialog.show();
        }
    }
}
